package com.meisiabc.app.repository.db.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meisiabc.app.repository.db.entity.CurriculumSchedule;
import com.meisiabc.app.repository.db.entity.PurchaseCourse;
import com.meisiabc.app.repository.db.entity.Student;
import com.meisiabc.app.repository.db.mapper.CurriculumScheduleMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CurriculumScheduleManager extends ServiceImpl<CurriculumScheduleMapper, CurriculumSchedule> {
    public List<CurriculumSchedule> selectByPurchaseCourseId(String purchaseCourseId) {
        return list(new QueryWrapper<CurriculumSchedule>().eq("purchase_course_id", purchaseCourseId).orderByAsc("id"));
    }

    public List<CurriculumSchedule> selectByPurchaseCourseIdPeriod(String purchaseCourseId, String startTime, String endTime) {
        return list(new QueryWrapper<CurriculumSchedule>().eq("purchase_course_id", purchaseCourseId).ge("class_date", startTime).lt("class_date", endTime));
    }

    public CurriculumSchedule getTail(String purchaseCourseId) {
        return getOne(new QueryWrapper<CurriculumSchedule>().eq("purchase_course_id", purchaseCourseId).orderByDesc("id"));
    }

    public List<CurriculumSchedule> selectUnFinashedClasses(String begin,String end) {
        return list(new QueryWrapper<CurriculumSchedule>().isNull("state_name").eq("is_delete", 0).ge("class_date", begin).le("class_date",end));
    }

//  	<select id="getZoomIdByDate" parameterType="java.lang.String" resultType="java.util.Map">
//    select  t.zoomId,cs.id,cs.class_date,cs.class_time,cs.class_time_end,cs.video from curriculum_schedule cs left join teacher t on t.uniqueid=cs.teacher_id where cs.state=7 and class_date>=#{classDate}
//    </select>
//
//	<update id="updateVideo" parameterType="java.util.Map">
//    update curriculum_schedule set video = #{video} where id= #{id};
//	</update>

    public List<CurriculumSchedule> getZoomIdByDate(String classDate){
        return list(new QueryWrapper<CurriculumSchedule>().eq("state", 7).ge("class_date", classDate));
    }

    public void updateVedio(Integer id,String video){
        update(CurriculumSchedule.builder().video(video).build(), new QueryWrapper<CurriculumSchedule>().eq("id", id));
    }
}
